package com.example.shop_car_2208.adapter

import android.graphics.Color
import android.graphics.ColorFilter
import android.graphics.drawable.ColorDrawable
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.shop_car_2208.R
import com.example.shop_car_2208.entity.CateEntity

class OneAdapter:BaseQuickAdapter<CateEntity,BaseViewHolder>(R.layout.item_one) {
    private var selecedId = 1//默认选中的id
    override fun convert(holder: BaseViewHolder, item: CateEntity) {
        holder.setText(R.id.cate_tv,item.category_name)
        holder.getView<TextView>(R.id.cate_tv).background = if (selecedId == item.id){
            ColorDrawable(Color.YELLOW)
        }else null
        holder.getView<TextView>(R.id.cate_tv).setTextColor(if (selecedId == item.id){
                Color.RED
        }else{Color.BLACK})
    }
    fun setSelectedId(id:Int){
        selecedId = id
        notifyDataSetChanged()
    }
}